package meihua.stopcarapp.model;

import meihua.mylibrary.basebean.ResultModel;
import meihua.mylibrary.baserx.RxSchedulers;
import meihua.stopcarapp.api.Api;
import meihua.stopcarapp.api.URLType;
import meihua.stopcarapp.bean.result.UserResult;
import meihua.stopcarapp.presenter.contract.LoginContract;
import rx.Observable;
import rx.functions.Func1;

/**
 * Name: LGZ
 * Time: 2017/5/9.
 * Dec:
 */

public class LoginModel implements LoginContract.Model {

    @Override
    public Observable<String> sendCode(String phone) {
        return Api.getDefault(URLType.STOPCAR_URL)
                .sendCode(phone)
                .map(new Func1<ResultModel<String>, String>() {
                    @Override
                    public String call(ResultModel<String> codeResultModel) {
                        String str = codeResultModel.getData();
                        return str;
                    }
                })
                .compose(RxSchedulers.<String>io_main());
    }

    @Override
    public Observable<UserResult> login(String phone, String code) {
        return Api.getDefault(URLType.STOPCAR_URL)
                .login(phone, code)
                .map(new Func1<ResultModel<UserResult>, UserResult>() {
                    @Override
                    public UserResult call(ResultModel<UserResult> userResultModel) {
//                        String str = codeResultModel.getData();
                        return userResultModel.getData();
                    }
                })
                .compose(RxSchedulers.<UserResult>io_main());
    }
}
